#pragma once
#include <iostream>
#include <sys/epoll.h>
#include "Log.hpp"
#include "Comm.hpp"
using namespace LogModule;

class Epoller
{
    const static int _revs_num = 64;
public:
    Epoller()
    {

    }
    void Init()
    {
        _epfd = epoll_create(256);
        if(_epfd<0)
        {
            LOG(LogLevel::ERROR)<<"epoll_create error";
            exit(EPOLL_CREATE_ERR);
        }
    }
    void CTL(int op,int fd,struct epoll_event* ev)
    {
        int ret = epoll_ctl(_epfd,op,fd,ev);
        if(ret<0)
        {
            LOG(LogLevel::ERROR)<<"epoll_ctl error";
        }
    }
    int Wait(struct epoll_event revs[],int revs_num)
    {
        int n = epoll_wait(_epfd,revs,revs_num,-1);
        if(n<0)
        {
            LOG(LogLevel::ERROR)<<"epoll_wait error";
        }
        else if(n==0)
        {
            LOG(LogLevel::DEBUG)<<"time out....";
        }
        return n;
    }
    ~Epoller()
    {

    }
private:
    int _epfd;
    struct epoll_event _revs[_revs_num];
};